package com.chainshop.procurement.utils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.atomic.AtomicInteger;

public class OrderNumberGenerator {
    private static final AtomicInteger sequence = new AtomicInteger(0);
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");

    public static String generateOrderNumber() {
        LocalDate date = LocalDate.now();
        String currentDate = formatter.format(date);

        int nextSequence = sequence.incrementAndGet();
        String orderNumber = currentDate + String.format("%04d", nextSequence);

        return orderNumber;
    }

    public static void main(String[] args) {
        String orderNumber = generateOrderNumber();
        System.out.println(orderNumber);
    }
}
